﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace DAL
{
    public class Log
    {
        //private const String SConn = "Data Source=DUCLINH-PC;Initial Catalog=HOUSMS;Persist Security Info=True;User ID=sa;Password=minhduc";
        private static string SConn = ConfigurationManager.ConnectionStrings["DucLM"].ConnectionString;
        public void AddLog(string tenThanhVien, string tenSuKien, DateTime ngayGio, string lyDo)
        {
            
            var conn = new SqlConnection(SConn);
            conn.Open();
            var cmd = new SqlCommand("AddLog", conn);
            cmd.CommandType = CommandType.StoredProcedure;
            try
            {
                cmd.Parameters.AddWithValue("@TenThanhVien", tenThanhVien);
                cmd.Parameters.AddWithValue("@TenSuKien", tenSuKien);
                cmd.Parameters.AddWithValue("@NgayGio", ngayGio);
                cmd.Parameters.AddWithValue("@LyDo", lyDo);
                cmd.ExecuteNonQuery();
            }
            finally
            {
                cmd.Dispose();
                conn.Close();
                conn.Dispose();
            }
        }

        public DataSet LoadLog()
        {
            var ds = new DataSet();
            var conn = new SqlConnection(SConn);
            var da = new SqlDataAdapter("LoadLog", conn);
            da.SelectCommand.CommandType = CommandType.StoredProcedure;
            da.Fill(ds);
            return ds;
        }
    }
}
